package de.nasch.platz.server;

import javax.jdo.PersistenceManager;

import com.google.gwt.user.server.rpc.RemoteServiceServlet;

import de.nasch.platz.client.KundendatenService;
import de.nasch.platz.shared.Kunde;

/**
 * The server side implementation of the RPC service.
 */
@SuppressWarnings("serial")
public class KundendatenServiceImpl extends RemoteServiceServlet implements
		KundendatenService {

	public String setKundendaten(String name) throws IllegalArgumentException {
		
		Kunde kunde = new Kunde();
		kunde.setName(name);
		PersistenceManager pm = PMF.get().getPersistenceManager();
        try {
            pm.makePersistent(kunde);
            return "true";
        }
        catch(Exception e){
        	return "false";
        }
        finally {
            pm.close();
        }
		
		
	}

	/**
	 * Escape an html string. Escaping data received from the client helps to
	 * prevent cross-site script vulnerabilities.
	 * 
	 * @param html the html string to escape
	 * @return the escaped string
	 */
	private String escapeHtml(String html) {
		if (html == null) {
			return null;
		}
		return html.replaceAll("&", "&amp;").replaceAll("<", "&lt;")
				.replaceAll(">", "&gt;");
	}
}
